package cn.aiweiyi.qingjing.coupon.distribution.feign.hystrix;

import cn.aiweiyi.qingjing.coupon.comm.exception.CouponException;
import cn.aiweiyi.qingjing.coupon.comm.vo.CommonResponse;
import cn.aiweiyi.qingjing.coupon.comm.vo.SettlementInfo;
import cn.aiweiyi.qingjing.coupon.distribution.feign.SettlementClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author 青衿
 * @Date 2020/11/21 14:43
 * 结算微服务降级策略实现
 **/
@Slf4j
@Component
public class SettlementClientHystrix implements SettlementClient {


    /**
     * 该方法在Feign调用tempalte微服务同名接口出错时,被Hystrix调用,降级
     *
     * @param settlement
     * @return
     * @throws CouponException
     */
    @Override
    public CommonResponse<SettlementInfo> couputeRule(SettlementInfo settlement) throws CouponException {
        log.error("向settlement模块computeRule请求时出现错误");

        settlement.setEmploy(false);
        settlement.setCost(-1.0);
        return new CommonResponse<>(-1,
                "向template模块findAllUsableTemplate请求时出现错误",
                settlement);
    }
}
